//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Validation Application Block
//===============================================================================

using System;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design;
using EntLibContrib.Validation.Configuration.Design.UI;

namespace EntLibContrib.Validation.Configuration.Design
{
	/// <summary>
	/// Add Type From String Node Command
	/// </summary>
	public class AddTypeFromStringNodeCommand : AddTypeNodeCommand
	{
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="AddTypeFromStringNodeCommand"/> class.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		public AddTypeFromStringNodeCommand(IServiceProvider serviceProvider)
			: base(serviceProvider)
		{
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// Gets the type that should be used to create the new <see cref="T:Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.Design.TypeNode"/>.
		/// </summary>
		/// <value></value>
		protected override Type SelectedType
		{
			get
			{
				using (TypeNameUI dialog = new TypeNameUI())
				{
					if (DialogResult.OK == dialog.ShowDialog())
					{
						return dialog.SelectedType;
					}
				}
				return null;
			}
		}
		#endregion
	}
}
